package com.yiwei.zxp.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.BuyerGoodDetailsV2Activity;
import com.yiwei.zxp.api.model.ShopMallListModel;
import com.yiwei.zxp.util.GlideRoundTransform;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class ShopInfoImageAdapter extends ItemAdapter<ShopMallListModel.DatasBean, ShopInfoImageAdapter.DefaultHolder> {


    private GlideRoundTransform transformation;
    private Context context;
    public ShopInfoImageAdapter(Context context) {
        super(context);
        this.context = context;
        transformation = new GlideRoundTransform(context, 3);
        //只是绘制左上角和右上角圆角
        transformation.setExceptCorner(false, false, true, true);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_shop_info_image, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ShopMallListModel.DatasBean item = getItem(position);
        holder.txtRank.setText((position + 1) + "");
        holder.txtMoney.setText("￥" + item.price);
        holder.txtTitle.setText(item.title);
        if (item.photos != null && item.photos.size() != 0) {
            Glide.with(context).load(item.photos.get(0)).asBitmap().centerCrop().transform(transformation).placeholder(R.color.image_default).into(holder.imgGoods);
        }
        holder.imgGoods.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BuyerGoodDetailsV2Activity.class);
                intent.putExtra("goods_id", item.goods_id);
                intent.putExtra("goods_no", item.goods_no);
                context.startActivity(intent);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_goods)
        ImageView imgGoods;
        @BindView(R.id.txt_rank)
        TextView txtRank;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_money)
        TextView txtMoney;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
